import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.awt.GLCanvas;
import com.jogamp.opengl.util.FPSAnimator;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;

/**
 * Created by WheelChen on 2017/5/20.
 */
public class test {
    public static void main(String[] args) {
        JFrame f = new JFrame("GUI TEST");
        f.setSize(800, 600);
        //居中
        f.setLocationRelativeTo(null);
        //JFrame绝对定位
        f.setLayout(null);

        //左边按钮区
        JPanel pLeft = new JPanel();
        pLeft.setBounds(50, 50, 300, 60);
        pLeft.setBackground(Color.RED);
        pLeft.setLayout(new FlowLayout());

        JButton b1 = new JButton("线条");
        JButton b2 = new JButton("三角形");
        JButton b3 = new JButton("矩形");
        JButton b4 = new JButton("旋转");
        JButton b5 = new JButton("平移");
        JButton b6 = new JButton("缩放");
//        b1.addActionListener(new ActionListener() {
//            @Override
//            public void actionPerformed(ActionEvent e) {
//                JDialog d = new JDialog(f);
//                d.setTitle("这是一个模态窗口");
//                d.setModal(true);
//                d.setSize(200, 150);
//                d.setLocationRelativeTo(f);
//                d.setVisible(true);
//            }
//        });
        b1.addActionListener((e) -> {
            JDialog d = new JDialog(f);
            JPanel jp = new JPanel();
//            JTextField tfName = new JTextField("");
//            tfName.setPreferredSize(new Dimension(80, 30));
//            d.add(lName);
//            d.add(tfName);

            d.setTitle("这是一个模态窗口");
            d.setModal(true);
            d.setSize(500, 250);
            d.setLocationRelativeTo(f);

            JButton b =new JButton("锁定大小");
            JLabel lName = new JLabel("x");
            JTextField tfName = new JTextField("");
            tfName.setPreferredSize(new Dimension(80, 10));
            jp.add(lName);
            jp.add(tfName);
            d.add(jp);
//            d.add(tfName);
            d.setVisible(true);
        });
        pLeft.add(b1);
        pLeft.add(b2);
        pLeft.add(b3);
        pLeft.add(b4);
        pLeft.add(b5);
        pLeft.add(b6);

        //中间显示区
        JPanel pMiddle = new JPanel();

        final GLProfile profile = GLProfile.get(GLProfile.GL2);
        GLCapabilities capabilities = new GLCapabilities(profile);
        // The canvas
        final GLCanvas glcanvas = new GLCanvas(capabilities);
        glcanvas.setSize(700, 600);

        Shape shape = new Shape();
        glcanvas.addGLEventListener(shape);

        pMiddle.add(glcanvas);
//        shape.showShape(b1, 1);
        shape.showShape(b2, 2);
        shape.showShape(b3, 3);
        shape.setRotate(b4);
        shape.setMove(b5);
        shape.setScale(b6);
        //pMiddle.setBackground(Color.BLUE);
        pMiddle.setBounds(10, 150, 300, 60);

        //右边参数输入区
        JPanel pRight = new JPanel();

        //分割线
        JSplitPane sp2 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true,pMiddle, pRight);
        JSplitPane sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, pLeft, sp2);
        // 设置分割条的位置
        sp2.setDividerLocation(450);
        sp.setOneTouchExpandable(true);
        sp.setDividerSize(10);//设置分隔线宽度的大小，以pixel为计算单位。

        // 把sp当作ContentPane
        f.setContentPane(sp);
//        f.add(pLeft, BorderLayout.WEST);
//        f.add(pRight,BorderLayout.EAST);
//        f.add(pMiddle,BorderLayout.CENTER);
        //设置关闭方式 关闭窗体的时候，退出程序
        f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

        //对所有组件进行渲染 务必放在最后
        f.setVisible(true);
        //必须放在setVisible(true)之后

        //设定分割面板的左右比例
        sp.setDividerLocation(0.1);
        //保持窗体变化后比例不变
        sp.addComponentListener(new ComponentAdapter() {
            public void componentResized(ComponentEvent e) {
                sp.setDividerLocation(0.1);
            }
        });
//        sp2.setDividerLocation(0.8);

        final FPSAnimator animator = new FPSAnimator(glcanvas, 100,true );
        animator.start();
    }



}
